package com.example.project.controller;

import com.example.project.entity.Goods;
import com.example.project.service.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

/**
 * @author Lenovo
 * @version 1.0
 * @date 2025/5/7 17:28
 * @className GoodsController
 */
@Controller
public class GoodController {
    @Autowired
    private GoodsService goodsService;
    @GetMapping("/goods/{id}")
    public String goods(Model model, @PathVariable int id) {
        //通过id拿到对应的 商品数据
        Goods good = goodsService.findById(id);
        if(good!=null){
            model.addAttribute("goods", good);
            return "goods_view";
        }else{
            //返回错误页面
            return "error";
        }

    }
}

